package cn.edu.hbnu.spoc.dao;

import cn.edu.hbnu.spoc.pojo.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author sakura
 * @date 2018/03/01 10:56
 */
@Repository
public class UserDao {
    @Autowired
    private SessionFactory sessionFactory;

    private Session getSession() {
        return this.sessionFactory.openSession();
    }

    public List<User> listUsers() {
        Session session = this.getSession();
        String hql = "from User u";
        Query query = session.createQuery(hql);
        return query.list();
    }
}
